import pandas as pd
from pymysql.connections import Connection

from datareport.api.annotation.Font import Font
from datareport.impl.paragraph.base.BaseParagraph import BaseParagraph
from datareport.api.annotation.Style import style
from datareport.impl import StaticDF


@style()
class JiHua_GailLan_14(BaseParagraph):
    """
    时间分布
    """

    def __init__(self):
        super().__init__()
        self.fonts: [Font] = [Font(text='''根据每月月初各基层党支部上报的组织生活计划，全年全校累计计划开展'''),
                     Font(text='''场次''',bold=True),
                     Font(text='''2''',bold=True,superscript=True,size=12),
                     Font(text='''组织生活，平均''',bold=True),
                     Font(text='''场/月/支部。''',bold=True)
                     ]
        self.sort = 5
        self.section=2

    def plot(self, result, plt):
        pass

    def getData(self,result):
        pass

    def start(self,conn:Connection,year,plt):
        # cursor=conn.cursor()
        sql='''
        select *
        from t_meetingPlan
        where year(startTime)='{year}' and isPlan=1
        '''.format(year=year)
        df =pd.read_sql(sql,con=conn)
        mean=len(df)/(12*len(df['partyBranchName'].drop_duplicates()))
        self.fonts.insert(1,Font(text=str(len(df)),bold=True))
        self.fonts.insert(-1,Font(text=str(round(mean,1)),bold=True))




